//
//  NYExamineSectionHeaderView.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/9.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYExamineSectionHeaderView.h"
@interface NYExamineSectionHeaderView ()
@property(nonatomic, strong) QMUIButton *arrowImgBtn;
@property(nonatomic, strong) QMUIGhostButton *iconBtnView;
@property(nonatomic, strong) TTTAttributedLabel *titleLabel;
@end
@implementation NYExamineSectionHeaderView
- (void)setListModel:(NYExamineListModel *)listModel
{
        _listModel = listModel;
        self.titleLabel.text = listModel.gname;
        [self updateContent];
}
- (void)setupIconBtnView
{
        NSInteger index = self.listModel.sectionIndex % 3;
        switch (index) {
                case 0:
                {
                        [self.iconBtnView setImage:[UIImage yi_nian_ji] forState:(UIControlStateNormal)];
                }
                        break;
                case 1:
                {
                        [self.iconBtnView setImage:[UIImage er_nian_ji] forState:(UIControlStateNormal)];
                }
                        break;
                case 2:
                {
                        [self.iconBtnView setImage:[UIImage san_nian_ji] forState:(UIControlStateNormal)];
                }
                        break;
                        
                default:
                        break;
        }
}
- (void)updateContent
{
        [self setupIconBtnView];
        self.arrowImgBtn.selected = self.listModel.isExpend;
}
- (void)setupView
{
        [super setupView];
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.iconBtnView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.arrowImgBtn];
        self.contentView.qmui_borderPosition = QMUIBorderViewPositionBottom;
        
        [self.arrowImgBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.contentView);
                make.right.equalTo(self.contentView).offset(-__WGWidth(15));
        }];
        [self.iconBtnView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.contentView).offset(__WGWidth(15));
                make.centerY.equalTo(self.contentView);
                make.height.width.mas_equalTo(__WGHeight(30));
        }];
        [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.iconBtnView.mas_right).offset(__WGWidth(10));
                make.centerY.equalTo(self.iconBtnView);
                make.right.lessThanOrEqualTo(self.contentView).offset(-__WGWidth(20)).priorityLow();
        }];
        self.arrowImgBtn.selected = !self.listModel.isExpend;
        @weakify(self);
        [self jk_addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
                @strongify(self);
                if (self.actionBlock)
                {
                        self.listModel.expend = !self.listModel.isExpend;
                        self.arrowImgBtn.selected = self.listModel.isExpend;
                        self.actionBlock(self.listModel, self.listModel.isExpend);
                }
        }];
}
- (QMUIGhostButton *)iconBtnView
{
        if (_iconBtnView == nil) {
                _iconBtnView = [[QMUIGhostButton alloc] init];
                _iconBtnView.clipsToBounds = YES;
                _iconBtnView.ghostColor = [UIColor clearColor];
        }
        return _iconBtnView;
}
- (QMUIButton *)arrowImgBtn
{
        if (_arrowImgBtn == nil) {
                _arrowImgBtn = [[QMUIButton alloc] qmui_initWithImage:[UIImage jian_tou] title:nil];
                _arrowImgBtn.userInteractionEnabled = NO;
                [_arrowImgBtn setImage:[UIImage jian_tou] forState:(UIControlStateNormal)];
                [_arrowImgBtn setImage:[[UIImage jian_tou] imageByRotateRight90] forState:(UIControlStateSelected)];
                [_arrowImgBtn setSelected:YES];
        }
        return _arrowImgBtn;
}
- (TTTAttributedLabel *)titleLabel
{
        if (_titleLabel == nil) {
                _titleLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
                _titleLabel.font = WGSystem15Font;
                _titleLabel.textColor = UIColorHex(0x333333);
                _titleLabel.textInsets = UIEdgeInsetsMake(0, 0, 0, 0);
        }
        return _titleLabel;
}
@end
